package com.bjtech.web.action.management;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bjtech.dao.UtilDao;
import com.bjtech.web.action.LyheatBaseAction;

public class FushionReportAction extends LyheatBaseAction{

	private static final long serialVersionUID = 1L;

	private UtilDao utilDao;
	
	private ReportNode reportNode;
	
	public void prepare() throws Exception {
		
	}

	public UtilDao getUtilDao() {
		return utilDao;
	}

	public void setUtilDao(UtilDao utilDao) {
		this.utilDao = utilDao;
	}
	
	public String report1(){
		String i_s_year = this.getRequest().getParameter("i_s_year");
		String i_e_year = this.getRequest().getParameter("i_e_year");
		String proj_id = this.getRequest().getParameter("proj_id");
		Map s_map = new HashMap();
		s_map.put("i_year", i_s_year);
		s_map.put("proj_id", proj_id);
		List<HashMap> startList = this.utilDao.selectReport("selectBuildAnalysisResult", s_map);
		Map e_map = new HashMap();
		e_map.put("i_year", i_e_year);
		List<HashMap> endList = this.utilDao.selectReport("selectBuildAnalysisResult", e_map);
		reportNode = createReportNode(startList,endList,i_s_year,i_e_year);
		return "xmlNode";
	}

	private ReportNode createReportNode(List<HashMap> startList,List<HashMap> endList, String i_s_year, String i_e_year) {
		
		ReportNode graph = new ReportNode("graph");
		graph.setAttribute("caption", "楼栋耗热量分析");
		graph.setAttribute("xAxisName", "分摊域");
		graph.setAttribute("yAxisName", "耗热量");
		graph.setAttribute("numdivlines", "9");
		graph.setAttribute("divLineColor", "0");
		graph.setAttribute("formatNumberScale", "CCCCCC");
		graph.setAttribute("divLineAlpha", "80");
		graph.setAttribute("decimalPrecision", "0");
		graph.setAttribute("showAlternateHGridColor", "1");
		graph.setAttribute("AlternateHGridAlpha", "30");
		graph.setAttribute("AlternateHGridColor", "CCCCCC");
		graph.setAttribute("rotateYAxisName", "1");
		
		//categories
		ReportNode categories = new ReportNode("categories");
		
		ReportNode ds_start = new ReportNode("dataset");
		ds_start.setAttribute("seriesname", i_s_year);
		ds_start.setAttribute("color", "FDC12E");
		ReportNode ds_end = new ReportNode("dataset");
		ds_end.setAttribute("seriesname",i_e_year);
		ds_end.setAttribute("color", "56B9F9");
		
		//dataset
		for(int i=0;i<startList.size();i++){
			HashMap startMap = (HashMap)startList.get(i);
			HashMap endMap = (HashMap)endList.get(i);
			
			ReportNode category = new ReportNode("category");
			category.setAttribute("name", (String)startMap.get("area_name"));
			categories.addChild(category);
			
			ReportNode strat_temp = new ReportNode("set");
			strat_temp.setAttribute("value", ((BigDecimal)startMap.get("heat_num")).toString());
			ds_start.addChild(strat_temp);
			
			ReportNode end_temp = new ReportNode("set");
			end_temp.setAttribute("value", ((BigDecimal)endMap.get("heat_num")).toString());
			ds_end.addChild(end_temp);
		}
		graph.addChild(categories);
		graph.addChild(ds_start);
		graph.addChild(ds_end);
		return graph;
	}
	
	public String report2(){
		String i_s_year = this.getRequest().getParameter("i_s_year");
		String i_e_year = this.getRequest().getParameter("i_e_year");
		String i_build_id = this.getRequest().getParameter("i_build_id");
		Map<String,String> map = new HashMap<String,String>();
		map.put("i_s_year", i_s_year);
		map.put("i_e_year", i_e_year);
		map.put("i_build_id", i_build_id);
		List<HashMap> resultList = this.utilDao.selectReport("selectBuildUserAnalysisResult", map);
		reportNode = createUserReportNode(resultList,map);
		return "xmlNode";
	}

	private ReportNode createUserReportNode(List<HashMap> resultList,Map map) {
		ReportNode graph = new ReportNode("graph");
		graph.setAttribute("numdivlines", "9");
		graph.setAttribute("divLineColor", "0");
		graph.setAttribute("formatNumberScale", "CCCCCC");
		graph.setAttribute("divLineAlpha", "80");
		graph.setAttribute("decimalPrecision", "0");
		graph.setAttribute("showAlternateHGridColor", "1");
		graph.setAttribute("AlternateHGridAlpha", "30");
		graph.setAttribute("AlternateHGridColor", "CCCCCC");
		graph.setAttribute("caption", "用户用热对比");
		graph.setAttribute("xaxisname", "用户");
		graph.setAttribute("yaxisname", "基本热费");
		graph.setAttribute("rotateYAxisName", "1");
		
		//categories
		ReportNode categories = new ReportNode("categories");
		
		ReportNode ds_start = new ReportNode("dataset");
		ds_start.setAttribute("seriesname", (String)map.get("i_s_year"));
		ds_start.setAttribute("color", "FDC12E");
		ReportNode ds_end = new ReportNode("dataset");
		ds_end.setAttribute("seriesname", (String)map.get("i_e_year"));
		ds_end.setAttribute("color", "56B9F9");
		
		//dataset
		for(HashMap user_temp:resultList){
			ReportNode category = new ReportNode("category");
			category.setAttribute("name", (String)user_temp.get("house_num"));
			categories.addChild(category);
			
			ReportNode strat_temp = new ReportNode("set");
			strat_temp.setAttribute("value", ((BigDecimal)user_temp.get("s_base_heat_money")).toString());
			ds_start.addChild(strat_temp);
			
			ReportNode end_temp = new ReportNode("set");
			end_temp.setAttribute("value", ((BigDecimal)user_temp.get("e_base_heat_money")).toString());
			ds_end.addChild(end_temp);
		}
		graph.addChild(categories);
		graph.addChild(ds_start);
		graph.addChild(ds_end);
		return graph;
	}

	public ReportNode getReportNode() {
		return reportNode;
	}

	public void setReportNode(ReportNode reportNode) {
		this.reportNode = reportNode;
	}
	
}
